#include<bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5;
int t,n,a[N + 5],ans;
inline int read(){
    char x;
    int f = 1,res = 0;
    while(x = getchar()){
        if (x < '0' || x > '9')
            if (x == '-')
                f = -1;
            else
                break;
        if (x >= '0' && x <= '9')
           res = res * 10 + x - '0';
    }
    return res * f;
}
void dfs(int r,int b,int i,int sum){
    if (i == n + 1){
        ans = max(ans,sum);
        return ;
    }
    if (a[i] == r)
        dfs(r,b,i + 1,sum + r);
    else
        if (a[i] == b)
            dfs(r,b,i + 1,sum + b);
        else{
            dfs(a[i],b,i + 1,sum);
            dfs(r,a[i],i + 1,sum);
        }
    return ;
}
signed main(){
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    t = read();
    while(t--){
        n = read();
        for(int i = 1;i <= n;i++)
            a[i] = read();
        ans = 0;
        dfs(0,0,1,0);
        cout << ans << endl;
    }
    return 0;
}